#include <fstream>
#include "spline.h"
#include <iostream>
using namespace std;

int main()
{
  ofstream proE;
  proE.open("proE.txt", std::ios::out);
  for (int n=10;n<=160;n=4*n)
    {
      vector<double> x;
      vector<double> y;
      int cc=n/2-2;
      if (cc % 2 == 0)
	{
	  
	  for (int i=0;i<=cc/2+1;i++)
	    {
	      double xp=i*(pow(3,0.5)/(cc/2+1));
	      x.push_back(xp);
	      double yp=(2*(pow(3-xp*xp,0.5)+pow(abs(xp),0.5)))/3;
	      y.push_back(yp);
	    }
	  for (int i=1;i<=cc/2;i++)
	    {
	      double xp=pow(3,0.5)-i*(pow(3,0.5)/(cc/2+1));
	      x.push_back(xp);
	      double yp=(2*(-pow(3-xp*xp,0.5)+pow(abs(xp),0.5)))/3;
	      y.push_back(yp);
	    }
	  for (int i=0;i<=cc/2+1;i++)
	    {
	      double xp=-i*(pow(3,0.5)/(cc/2+1));
	      x.push_back(xp);
	      double yp=(2*(-pow(3-xp*xp,0.5)+pow(abs(xp),0.5)))/3;
	      y.push_back(yp);
	    }
	  for (int i=1;i<cc/2+1;i++)
	    {
	      double xp=-pow(3,0.5)+i*(pow(3,0.5)/(cc/2+1));
	      x.push_back(xp);
	      double yp=(2*(pow(3-xp*xp,0.5)+pow(abs(xp),0.5)))/3;
	      y.push_back(yp);
	    }
	}
      else
	{
	  
	  for (int i=0;i<=(cc+1)/2+1;i++)
	    {
	      double xp=i*(pow(3,0.5)/((cc+1)/2+1));
	      x.push_back(xp);
	      double yp=(2*(pow(3-xp*xp,0.5)+pow(abs(xp),0.5)))/3;
	      y.push_back(yp);
	    }
	  for (int i=1;i<=(cc-1)/2;i++)
	    {
	      double xp=pow(3,0.5)-i*(pow(3,0.5)/((cc+1)/2));
	      x.push_back(xp);
	      double yp=(2*(-pow(3-xp*xp,0.5)+pow(abs(xp),0.5)))/3;
	      y.push_back(yp);
	    }
	  for (int i=0;i<=(cc+1)/2;i++)
	    {
	      double xp=-i*(pow(3,0.5)/((cc+1)/2));
	      x.push_back(xp);
	      double yp=(2*(-pow(3-xp*xp,0.5)+pow(abs(xp),0.5)))/3;
	      y.push_back(yp);
	    }
	  for (int i=1;i<(cc+1)/2+1;i++)
	    {
	      double xp=-pow(3,0.5)+i*(pow(3,0.5)/((cc+1)/2+1));
	      x.push_back(xp);
	      double yp=(2*(pow(3-xp*xp,0.5)+pow(abs(xp),0.5)))/3;
	      y.push_back(yp);
	    }
	}

	  
      Curve S(n,x,y);
      vector<double> Plotx;
      vector<double> Ploty;
      int c=0;
      for (int k=0;k<=n-1;k++)
	{
	  
	  double sub=(S.t[k+1]-S.t[k])/10;
	  for (int s=0;s<10;s++)
	    {
	      double tt=S.t[k]+s*sub;
	      double plotx;
	      plotx=S.answer[k].coe[0]+S.answer[k].coe[1]*tt+S.answer[k].coe[2]*tt*tt+S.answer[k].coe[3]*tt*tt*tt;
	      double ploty;
	      ploty=S.answer_[k].coe[0]+S.answer_[k].coe[1]*tt+S.answer_[k].coe[2]*tt*tt+S.answer_[k].coe[3]*tt*tt*tt;
	      Plotx.push_back(plotx);
	      Ploty.push_back(ploty);
	      c=c+1;
	    }
	      if (k==n-1)
		{
		  double tt=S.t[k+1];
		  double plotx;
		  plotx=S.answer[k].coe[0]+S.answer[k].coe[1]*tt+S.answer[k].coe[2]*tt*tt+S.answer[k].coe[3]*tt*tt*tt;
		  double ploty;
		  ploty=S.answer_[k].coe[0]+S.answer_[k].coe[1]*tt+S.answer_[k].coe[2]*tt*tt+S.answer_[k].coe[3]*tt*tt*tt;
		  Plotx.push_back(plotx);
		  Ploty.push_back(ploty);

		}
	    
	}
      proE << "----------" << " N = " << n <<" ----------" <<endl;
      proE << "x:" <<endl;
      for (int i=0;i<=c;i++)
	{
	  proE << Plotx[i] << " ";
	}
      proE << endl;
      proE << "y:" <<endl;
      for (int i=0;i<=c;i++)
	{
	  proE << Ploty[i] << " ";
	}
      proE << endl;
    }
  
}
